function heliVisInstruct(av, logic)
% Run a PredInfAV object through its paces, without user input.

%% use the same random seed for all demos
startSeed=65
isClient=1;
delay=1;
isCell=1;
fullscreen=0;


if nargin < 1 || isempty(av)
    av = PredInfAVhelicopter();
end

if nargin < 2 || isempty(logic)
    logic = PredInfLogic();
end

sigma=10
bucketSDs = 3; % width of the bucket, in SDs of the payoff distribution
av.holeWidth = bucketSDs*av.width * sigma/logic.maxOutcome; % set bucket width
av.explStd = av.width * sigma/logic.maxOutcome; % set payoff SD = noise SD


clear logic
logic = PredInfLogic(startSeed);
av.logic=logic;

%% setup logic and AV classes
[logic av]=setupInstructions(logic, av, 0)

%% Run through some  blocks and trials

% get struct arrays big enough to hold all the data
logic.startSession();
[statusData, payoutData] = logic.getDataArrays();
av.logic = logic;

% start up with a drawing window
av.drawables.automateObjectMethod( ...
    'draw', @dotsDrawable.drawFrame, {}, [], isCell);

drawables = dotsEnsembleUtilities.makeEnsemble('drawables', isClient);

% tell the drawables ensemble how to open and close a drawing window
drawables.addCall({@dotsTheScreen.openWindow}, 'open');
isCell = true;

drawables.addObject(av.drawables)

drawables.automateObjectMethod( ...
    'draw', @dotsDrawable.drawFrame, {}, [], isCell);

% dotsTheDrawablesManager.reset();
% dm = dotsTheDrawablesManager.theObject();
% dm.openScreenWindow();
% dm.mayDrawNextFrame(true);

av.pleasePressString='Catch coins to win money!';
av.pleaseWaitString='Coin bags fall under helicopter'


drawables.addCall({@dotsTheScreen.closeWindow}, 'close');

if fullscreen==1
 drawables.addCall({@dotsTheScreen.reset, 'displayIndex', 1}, 'fullscreen');
 drawables.callByName('fullscreen');
end


% Open an OpenGL window
drawables.callByName('open');

% Let each drawable object draw in the window
%drawables.callByName('draw');
%pause(delay);


% drawables.addObject(frame);
% drawables.addObject(ornaments);
% drawables.addObject(greeting);
% 
 av.initialize()



% do preliminary things
% dm.activateGroup(av.instructionGroup);
av.doPreviousInstruction();
av.doMessage('Catch coins to win money!');
av.doNextInstruction();
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end


av.doNextInstruction();
av.doMessage('Coin bags fall under helicopter');
while ~exist('rr', 'var')
    rr=input('', 's')
    pause(.1)
end


av.doMessage('Place bucket under the helicopter to catch coins');

while ~exist('rrr', 'var')
    rrr=input('', 's')
    pause(.1)
end
av.doMessage();


av.doMessage('Like this:');
clear rrr
while ~exist('rrr', 'var')
    rrr=input('', 's')
    pause(.1)
end
av.doMessage();


[av logic]=runInstructions(av, logic, 1)


% do preliminary things
%dm.activateGroup(av.instructionGroup);
av.doMessage('Chasing bags earns less money...');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end


clear logic
logic = PredInfLogic(startSeed);
av.logic=logic;

[logic av]=setupInstructions(logic, av, 0)


% do preliminary things
% dm.activateGroup(av.instructionGroup);
%av.doPreviousInstruction();
av.doMessage('Chasing bags earns less money...');
%av.doNextInstruction();
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
 logic.blockScore=0;
 
sigma=10
bucketSDs = 3; % width of the bucket, in SDs of the payoff distribution
av.holeWidth = bucketSDs*av.width * sigma/logic.maxOutcome; % set bucket width
av.explStd = av.width * sigma/logic.maxOutcome; % set payoff SD = noise SD

[av logic]=runInstructions(av, logic, 2)





%% Show example with change-point


clear logic
logic = PredInfLogic(startSeed);
av.logic=logic;

[logic av]=setupInstructions(logic, av, 1)
% do preliminary things
% dm.activateGroup(av.instructionGroup);
av.doMessage('Sometimes helicopter will move');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;


av.doMessage('And you should move your bucket under it');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;

av.doMessage('Like this:');
clear rrr
while ~exist('rrr', 'var')
    rrr=input('', 's')
    pause(.1)
end
av.doMessage();

 
sigma=10
bucketSDs = 3; % width of the bucket, in SDs of the payoff distribution
av.holeWidth = bucketSDs*av.width * sigma/logic.maxOutcome; % set bucket width
av.explStd = av.width * sigma/logic.maxOutcome; % set payoff SD = noise SD

[av logic]=runInstructions(av, logic, 1)




















clear logic
logic = PredInfLogic(startSeed);
av.logic=logic;

[logic av]=setupInstructions(logic, av, 0)
sigma=25
logic.blockStds=sigma;



% do preliminary things
% dm.activateGroup(av.instructionGroup);
%av.doPreviousInstruction();
av.doMessage('On windy days bags will be more scattered...');
%av.doNextInstruction();
pause(2)
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end

av.doMessage('Like this:');
clear rrr
while ~exist('rrr', 'var')
    rrr=input('', 's')
    pause(.1)
end
av.doMessage();

logic.blockScore=0;
% control the spatial cost function
bucketSDs = 3; % width of the bucket, in SDs of the payoff distribution
av.holeWidth = bucketSDs*av.width * sigma/logic.maxOutcome; % set bucket width
av.explStd = av.width * sigma/logic.maxOutcome; % set payoff SD = noise SD



[av logic]=runInstructions(av, logic, 1)





%% cloudy demo




clear logic
logic = PredInfLogic(startSeed);
av.logic=logic;

[logic av]=setupInstructions(logic, av, 1, 1)
% do preliminary things
% dm.activateGroup(av.instructionGroup);
av.doMessage('Now it is cloudy');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;


av.doMessage('You cannot see the helicopter');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;


av.doMessage('but move your bucket to where you think it is');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;

av.doMessage('Like this:');
clear rrr
while ~exist('rrr', 'var')
    rrr=input('', 's')
    pause(.1)
end
av.doMessage();
 
sigma=10
bucketSDs = 3; % width of the bucket, in SDs of the payoff distribution
av.holeWidth = bucketSDs*av.width * sigma/logic.maxOutcome; % set bucket width
av.explStd = av.width * sigma/logic.maxOutcome; % set payoff SD = noise SD

[av logic]=runInstructions(av, logic, 3)


%% cloudy with catch trials

clear logic
logic = PredInfLogic(startSeed);
av.logic=logic;

[logic av]=setupInstructions(logic, av, 1, 1)
%logic.catchTrialProbability=.2;

% do preliminary things
%dm.activateGroup(av.instructionGroup);
av.doMessage('Sometimes the clouds part');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;


av.doMessage('And the helicopter becomes visible');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;


av.doMessage('Giving you perfect information about its location');
clear r
while ~exist('r', 'var')
    r=input('', 's')
    pause(.1)
end
logic.blockScore=0;

av.doMessage('Like this:');
clear rrr
while ~exist('rrr', 'var')
    rrr=input('', 's')
    pause(.1)
end
av.doMessage();
 
sigma=10
bucketSDs = 3; % width of the bucket, in SDs of the payoff distribution
av.holeWidth = bucketSDs*av.width * sigma/logic.maxOutcome; % set bucket width
av.explStd = av.width * sigma/logic.maxOutcome; % set payoff SD = noise SD

[av logic]=runInstructions(av, logic, 4)




% Clean up
drawables.callByName('close');



%dm.closeScreenWindow();